<!--
 * @description  :情报管理 - 反馈详情
 * @descriptionDetail:情报管理 -反馈详情
 * @copyright    : 浙江烟草
 * @author       : sy
 * @create       : 2023-08-23 16:21:21
-->
<template>
  <view class="page">
    <!-- #ifdef H5-ONLY -->
    <theme-navbar
      :is-white="false"
      :title="navTitle"
      :custom-back="goBack"
      style="z-index: 99999"
    >
    </theme-navbar>
    <!-- #endif -->
    <view class="content u-page">
      <u-form ref="uForm" :model="detailForm" label-position="top" label-width="auto" :error-type="errorType">
        <u-form-item
          label="情报线索编号"
          prop="clueCode"
          :required="isRequired"
          label-position="top"
        >
          <u-input placeholder="" :disabled="true" v-model="detailForm.clueCode"></u-input>
        </u-form-item>
        <u-form-item
          label="反馈单位名称"
          prop="feedbackOrgName"
          :required="isRequired"
          label-position="top"
        >
          <u-input placeholder="" :disabled="true" v-model="detailForm.feedbackOrgName"></u-input>
        </u-form-item>
        <u-form-item
          label="是否关联案件"
          prop="isRelationCaseName"
          :required="isRequired"
          label-position="left"
        >
          <u-input input-align="right" placeholder="" :disabled="true" v-model="detailForm.isRelationCaseName"></u-input>
        </u-form-item>
        <u-form-item
          label="关联案件编号"
          prop="caseCode"
          :required="isRequired"
          label-position="top"
        >
          <u-input placeholder="" :disabled="true" v-model="detailForm.caseCode"></u-input>
        </u-form-item>
        <u-form-item
          label="是否办结"
          prop="isCloseName"
          :required="isRequired"
          label-position="left"
        >
          <u-input input-align="right" placeholder="" :disabled="true" v-model="detailForm.isCloseName"></u-input>
        </u-form-item>
        <u-form-item
          label="反馈时间"
          prop="feedbackTime"
          :required="isRequired"
          label-position="left"
        >
          <u-input input-align="right" placeholder="" :disabled="true" v-model="detailForm.feedbackTime"></u-input>
        </u-form-item>
        <u-form-item
          label="反馈人岗位"
          prop="feedbackPersonPost"
          :required="isRequired"
          label-position="left"
        >
          <u-input input-align="right" placeholder="" :disabled="true" v-model="detailForm.feedbackPersonPost"></u-input>
        </u-form-item>
        <u-form-item
          label="反馈人"
          prop="feedbackPersonName"
          :required="isRequired"
          label-position="left"
        >
          <u-input input-align="right" placeholder="" :disabled="true" v-model="detailForm.feedbackPersonName"></u-input>
        </u-form-item>
        
        <u-form-item
          label="走私烟(万支)"
          label-position="left"
        >
          <u-input input-align="right" placeholder="" :disabled="true" v-model="detailForm.smuggleQty"></u-input>
        </u-form-item>
        <u-form-item
          label="烟机(台)"
          label-position="left"
        >
          <u-input input-align="right" placeholder="" :disabled="true" v-model="detailForm.machineQty"></u-input>
        </u-form-item>
        <u-form-item
          label="烟叶烟丝(吨)"
          label-position="left"
        >
          <u-input input-align="right" placeholder="" :disabled="true" v-model="detailForm.tobaccoQty"></u-input>
        </u-form-item>
        <u-form-item
          label="其他涉案物品数量"
          label-position="left"
        >
          <u-input input-align="right" placeholder="" :disabled="true" v-model="detailForm.otherQty"></u-input>
        </u-form-item>
        <u-form-item
          label="货值金额(万元)"
          label-position="left"
        >
          <u-input input-align="right" placeholder="" :disabled="true" v-model="detailForm.goodsMoney"></u-input>
        </u-form-item>
        <u-form-item
          label="涉案金额(万元)"
          label-position="left"
        >
          <u-input input-align="right" placeholder="" :disabled="true" v-model="detailForm.caseTotalVal"></u-input>
        </u-form-item>
        <u-form-item
          label="反馈内容"
          :required="isRequired"
          prop="content" 
          label-position="top"
        >
          <u-input type="textarea" maxlength="340" :disabled="isDisabled" v-model="detailForm.content" placeholder="请输入反馈内容"></u-input>
        </u-form-item>
      </u-form>
    </view>
    <view class="space-content"></view>
    <!-- 底部按钮开始 -->
    <view class="submit-btns btn-other-cls">
      <u-button plain class="u-btn" type="primary" @click="goBack()">
        取消
      </u-button>
      <u-button v-if="!isDisabled" class="u-btn" type="primary" @click="handlerSave()">
        保存
      </u-button>
    </view>
    <!-- 底部按钮结束 -->
  </view>
</template>

<script>
import intelligenceservice from "@/service/intelligence/intelligence.service";
import commonService from "@/service/common/common.service";
export default {
  data() {
    return {
      isRequired:true,	
      detailForm:{},
      errorType: ["border-bottom","message",],
      rules:{
        clueCode: [{
          required: true,
          message: '请输入情报线索编号',
          // 可以单个或者同时写两个触发验证方式
          trigger: ['change', 'blur',],
        },],
        feedbackOrgName: [{
          required: true,
          message: '请输入反馈单位名称',
          // 可以单个或者同时写两个触发验证方式
          trigger: ['change', 'blur',],
        },],
        isRelationCaseName:[
          {
            required: true,
            message: '请选择是否关联案件',
            // 可以单个或者同时写两个触发验证方式
            trigger: ['change', 'blur',],
          },
        ],
        caseCode: [{
          // 自定义验证函数，见上说明
          validator: (rule, value, callback) => {
            if(this.detailForm.isRelationCase){
              return !this.$u.test.isEmpty(value);
            }else{
              return true;
            }
          },
          message: '请输入关联案件编号',
          // 触发器可以同时用blur和change
          trigger: ['change','blur',],
        },],
        isCloseName: [{
          required: true,
          message: '请输入是否办结',
          // 可以单个或者同时写两个触发验证方式
          trigger: ['change', 'blur',],
        },],
        feedbackTime:[{
          required: true,
          message: '请输入反馈时间',
          // 可以单个或者同时写两个触发验证方式
          trigger: ['change', 'blur',],
        },],
        // feedbackPersonPost:[{
        //   required: true,
        //   message: '请输入反馈人岗位',
        //   // 可以单个或者同时写两个触发验证方式
        //   trigger: ['change', 'blur',],
        // },],
        feedbackPersonName:[{
          required: true,
          message: '请输入反馈人',
          // 可以单个或者同时写两个触发验证方式
          trigger: ['change', 'blur',],
        },],
        content: [{
          required: true,
          message: '请输入反馈内容',
          // 可以单个或者同时写两个触发验证方式
          trigger: ['change', 'blur',],
        },
        {
          max: 500,
          message: '反馈内容超出固定长度',
          trigger: ['change', 'blur',],
        },],
      },
      uuid:'', // 唯一标识id
      formType: 'feedbackDetail',
      isDisabled:true,
    }
  },
  onReady() {
    this.$refs.uForm.setRules(this.rules);
  },
  onLoad(opt) {
    this.uuid = opt.uuid;
    this.formType = opt.formType ? opt.formType : 'feedbackDetail';
    if(this.uuid){
      if(this.formType == 'feedback'){
        this.isDisabled = false;
        this.getCludFeedbackInfo();
      }else{
        this.findById();
      }
    }
  },
  created() {
    if(this.formType == 'feedback'){
      this.updateMixinTitle('情报反馈');
    }else{
      this.updateMixinTitle('情报反馈详情');
    }
  },
  methods: {
    // 反馈详情
    findById(){
      this.$modal.showLoading("加载中");
      intelligenceservice.findById({id: this.uuid, }).then((res) => {
        this.$modal.hideLoading();
        if(res.success){
          this.formDataMerge(res.bean);
        }else{
          this.$u.toast(res.msg);
        }
      }).catch((err) => {
        this.$modal.hideLoading();
        this.$u.toast(err);
      });
    },
    // 反馈
    getCludFeedbackInfo(){
      this.$modal.showLoading("加载中");
      intelligenceservice.getCludFeedbackInfo({clueUuid: this.uuid, }).then((res) => {
        this.$modal.hideLoading();
        if(res.success){
          this.formDataMerge(res.bean);
        }else{
          this.$u.toast(res.msg);
        }
      }).catch((err) => {
        this.$modal.hideLoading();
        this.$u.toast(err);
      });
    },
    handlerSave(){
      this.$refs.uForm.validate(valid => {
        if(valid){
          this.$modal.showLoading("保存中");
          intelligenceservice.saveCludFeedbackInfo(this.detailForm).then((res) => {
            if(res.success){
              this.$u.toast("保存成功！");
              this.backPrev({
                paramKey:"refresh",
                param: true,
              },2);
            }else{
              this.$u.toast(res.msg);
            }
          }).catch((err) => {
  
          })
        }
      });
    },
    formDataMerge(bean){
      this.objMerge(this.detailForm,bean);
      this.detailForm.isRelationCaseName = this.detailForm.isRelationCase ? '是' : '否';
      this.detailForm.isCloseName = this.detailForm.isClose ? '是' : '否';
      this.detailForm.smuggleQty = this.detailForm.smuggleQty || 0;
      this.detailForm.machineQty = this.detailForm.machineQty || 0;
      this.detailForm.tobaccoQty = this.detailForm.tobaccoQty || 0;
      this.detailForm.otherQty = this.detailForm.otherQty || 0;
      this.detailForm.goodsMoney = this.detailForm.goodsMoney || 0;
      this.detailForm.caseTotalVal = this.detailForm.caseTotalVal || 0;
      this.getOrgName(this.detailForm.feedbackOrgUuid);
    },
    // 获取反馈单位名称
    getOrgName(orgUuid){
      commonService.getOrgs(orgUuid).then((res) => {
        if(res.success){
          this.detailForm.feedbackOrgName = res.data[0].orgName;
          this.$forceUpdate();
        }else{
          this.$u.toast(res.msg);
        }
      }).catch((err) => {
        this.$u.toast(err);
      })
    },
  },
}
</script>

<style scoped lang="scss">
.page{ padding: 0;}
.content{
  padding: $cm_conent_padding_column $cm_content_paddng_row;
}
</style>
